from rest_framework import serializers
from .models import *


# 品牌的序列化器
class BrandSer(serializers.ModelSerializer):
    id = serializers.IntegerField(read_only=True)
    logo = serializers.CharField(allow_null=True)

    class Meta:
        model = Brand
        fields = "__all__"


<<<<<<< HEAD
# 定义频道组的序列化器
class GroupSer(serializers.ModelSerializer):
    cate = serializers.PrimaryKeyRelatedField(queryset=Cate.objects.all())
    cate_name = serializers.SerializerMethodField(read_only=True)

    def get_cate_name(self, obj):
        return obj.cate.name

    class Meta:
        model = Group
        fields = "__all__"
        read_only_fields = ['id',]


# 商品类别的序列化器
=======
# 类别的序列化器
>>>>>>> f03f6fc2a5e389c57682ccb2441daf9bc7b6dbf9
class CateSer(serializers.ModelSerializer):
    class Meta:
        model = Cate
        fields = "__all__"


<<<<<<< HEAD
# SKU的序列化器
class SKUSer(serializers.ModelSerializer):

    cate = serializers.PrimaryKeyRelatedField(queryset=Cate.objects.all())
=======
# 频道组的序列化器
class GroupSer(serializers.ModelSerializer):
    # 分类的引用字段
    cate = serializers.PrimaryKeyRelatedField(queryset=Cate.objects.all())
    # 获取分类的名字
>>>>>>> f03f6fc2a5e389c57682ccb2441daf9bc7b6dbf9
    cate_name = serializers.SerializerMethodField(read_only=True)

    def get_cate_name(self, obj):
        return obj.cate.name

    class Meta:
<<<<<<< HEAD
        model = SKU
        fields = "__all__"
        read_only_fields = ["id", "detail", "image_default", "sales"]


# SPU 序列化器
class SPUSer(serializers.ModelSerializer):
    class Meta:
        model = SPU
        fields = "__all__"
=======
        model = Group
        fields = "__all__"


>>>>>>> f03f6fc2a5e389c57682ccb2441daf9bc7b6dbf9
